package com.cuij.util;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * 日期的工具类，用于获取当前时间
 * 
 * @author cuij
 */
public class DateUtil {

    private static String time = "yyyyMMddHHmmss";

    public static SimpleDateFormat yyyymmddhhmmss = new SimpleDateFormat(time);

    /**
     * 获取当前时间
     */
    public static String getCurrentTime() {
        return yyyymmddhhmmss.format(new Date());
    }

    /**
     * 获取默认结束时间
     */
    public static String getEndTime() {
        Date CurrentTime = new Date();
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(CurrentTime);
        calendar.add(Calendar.MINUTE, 30);
        CurrentTime = calendar.getTime();
        String endTime = yyyymmddhhmmss.format(CurrentTime);
        return endTime;
    }

    public static int betweenTime(String startTime, String endTime) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyymmddhhmmss");
        int betweenTime = 0;
        try {
            Date startDate = sdf.parse(startTime);
            Date endDate = sdf.parse(endTime);
            betweenTime = (int) (endDate.getTime() - startDate.getTime());
            betweenTime = betweenTime / 1000 / 60;
        }
        catch (Exception e) {

        }
        return betweenTime;
    }

    public static void main(String[] args) {
        System.out.println(getEndTime());
    }
}
